﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EislaufScb.Model.Repository.Organisation
{
    public class PersonRepository : BaseRepository, IPersonRepository
    {
        public PersonRepository(ClubModelContainer context) : base(context)
        {

        }

        public List<EislaufScb.Model.Person> GetPersonByType(string type)
        {
            List<Person> persons = new List<Person>();

            List<PersonRoleRelation> roles = context.BaseEntitySet.OfType<PersonRoleRelation>().Where(ro => ro.PersonType.Name.Contains(type)).ToList();

            foreach (var role in roles)
            {
                persons.Add(role.Person);
            }

            return persons;
        }

        public List<EislaufScb.Model.Person> GetPersonByFirstNameAndLastName(string firstName, string lastName)
        {
            return context.BaseEntitySet.OfType<Person>().Where(person => person.FirstName.Equals(firstName) && person.LastName.Equals(lastName)).ToList();
        }
    }
}
